home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / grep16.zip / GREP.DOC < prev    next >
Text File  |  1993-02-25  |  8KB  |  265 lines

  1.  
  2.  
  3.  
  4. GREP(1)                  USER COMMANDS                    GREP(1)
  5.  
  6.  
  7.  
  8. NAME
  9.      grep, egrep - print lines matching a regular expression
  10.  
  11. SYNOPSIS
  12.      grep [ -CVbchilnsvwx ] [ -_n_u_m ] [ -AB _n_u_m ] [ [ -e ] _e_x_p_r  |
  13.      -f _f_i_l_e ] [ _f_i_l_e_s ... ]
  14.  
  15. DESCRIPTION
  16.      _G_r_e_p searches the files listed in the arguments (or standard
  17.      input  if  no  files are given) for all lines that contain a
  18.      match for the given _e_x_p_r.  If  any  lines  match,  they  are
  19.      printed.
  20.  
  21.      Also, if any matches were found, _g_r_e_p exits with a status of
  22.      0, but if no matches were found it exits with a status of 1.
  23.      This is useful for building shell scripts that use _g_r_e_p as a
  24.      condition for, for example, the _i_f statement.
  25.  
  26.      When invoked as _e_g_r_e_p the syntax of  the  _e_x_p_r  is  slightly
  27.      different; See below.
  28.  
  29. REGULAR EXPRESSIONS
  30.           (grep)    (egrep)   (explanation)
  31.  
  32.           _c         _c         a   single   (non-meta)   character
  33.                               matches itself.
  34.  
  35.           .         .         matches any single character except
  36.                               newline.
  37.  
  38.           \?        ?         postfix operator;  preceeding  item
  39.                               is optional.
  40.  
  41.           *         *         postfix operator; preceeding item 0
  42.                               or more times.
  43.  
  44.           \+        +         postfix operator; preceeding item 1
  45.                               or more times.
  46.  
  47.           \|        |         infix  operator;   matches   either
  48.                               argument.
  49.  
  50.           ^         ^         matches the  empty  string  at  the
  51.                               beginning of a line.
  52.  
  53.           $         $         matches the empty string at the end
  54.                               of a line.
  55.  
  56.           \<        \<        matches the  empty  string  at  the
  57.                               beginning of a word.
  58.  
  59.           \>        \>        matches the empty string at the end
  60.  
  61.  
  62.  
  63. GNU Project       Last change: 1988 December 13                 1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. GREP(1)                  USER COMMANDS                    GREP(1)
  71.  
  72.  
  73.  
  74.                               of a word.
  75.  
  76.           [_c_h_a_r_s]   [_c_h_a_r_s]   match any character  in  the  given
  77.                               class; if the first character after
  78.                               [ is ^, match any character not  in
  79.                               the given class; a range of charac-
  80.                               ters   may    be    specified    by
  81.                               _f_i_r_s_t-_l_a_s_t; for example, \W (below)
  82.                               is   equivalent   to   the    class
  83.                               [^A-Za-z0-9]
  84.  
  85.           \( \)     ( )       parentheses are  used  to  override
  86.                               operator precedence.
  87.  
  88.           \_d_i_g_i_t    \_d_i_g_i_t    \_n matches a  repeat  of  the  text
  89.                               matched  earlier  in  the regexp by
  90.                               the subexpression  inside  the  nth
  91.                               opening parenthesis.
  92.  
  93.           \         \         any special character may  be  pre-
  94.                               ceded  by  a  backslash to match it
  95.                               literally.
  96.  
  97.           (the following are for compatibility with GNU Emacs)
  98.  
  99.           \b        \b        matches the  empty  string  at  the
  100.                               edge of a word.
  101.  
  102.           \B        \B        matches the empty string if not  at
  103.                               the edge of a word.
  104.  
  105.           \w        \w        matches word-constituent characters
  106.                               (letters & digits).
  107.  
  108.           \W        \W        matches  characters  that  are  not
  109.                               word-constituent.
  110.  
  111.      Operator precedence is (highest to lowest) ?, *, and +, con-
  112.      catenation, and finally |.  All other constructs are syntac-
  113.      tically identical  to  normal  characters.   For  the  truly
  114.      interested,  the  file  dfa.c describes (and implements) the
  115.      exact grammar understood by the parser.
  116.  
  117. OPTIONS
  118.      -A _n_u_m
  119.           print <num> lines of context after every matching line
  120.  
  121.      -B _n_u_m
  122.           print _n_u_m lines of context before every matching line
  123.  
  124.      -C   print 2 lines of context on each side of every match
  125.  
  126.  
  127.  
  128.  
  129. GNU Project       Last change: 1988 December 13                 2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. GREP(1)                  USER COMMANDS                    GREP(1)
  137.  
  138.  
  139.  
  140.      -_n_u_m print _n_u_m lines of context on each side of every match
  141.  
  142.      -V   print the version number on the diagnostic output
  143.  
  144.      -b   print every match preceded by its byte offset
  145.  
  146.      -c   print a total count of matching lines only
  147.  
  148.      -e _e_x_p_r
  149.           search for _e_x_p_r; useful if _e_x_p_r begins with -
  150.  
  151.      -f _f_i_l_e
  152.           search for the expression contained in _f_i_l_e
  153.  
  154.      -h   don't display filenames on matches
  155.  
  156.      -i   ignore case difference when comparing strings
  157.  
  158.      -l   list files containing matches only
  159.  
  160.      -n   print each match preceded by its line number
  161.  
  162.      -s   run silently producing no output except error messages
  163.  
  164.      -v   print only lines that contain no matches for the <expr>
  165.  
  166.      -w   print only lines where the match is a complete word
  167.  
  168.      -x   print only lines where the match is a whole line
  169.  
  170. SEE ALSO
  171.      emacs(1), ed(1), sh(1), _G_N_U _E_m_a_c_s _M_a_n_u_a_l
  172.  
  173. INCOMPATIBILITIES
  174.      The following incompatibilities with UNIX _g_r_e_p exist:
  175.  
  176.           The context-dependent meaning of *  is  not  quite  the
  177.           same (grep only).
  178.  
  179.           -b prints a byte offset instead of a block offset.
  180.  
  181.           The {_m,_n} construct of System  V  grep  is  not  imple-
  182.           mented.
  183.  
  184. BUGS
  185.      GNU _e?_g_r_e_p has been thoroughly debugged and  tested  over  a
  186.      period  of  several years; we think it's a reliable beast or
  187.      we wouldn't distribute it.  If by some fluke of the universe
  188.      you  discover  a bug, send a detailed description (including
  189.      options, regular expressions, and a copy of  an  input  file
  190.      that can reproduce it) to mike@ai.mit.edu.
  191.  
  192.  
  193.  
  194.  
  195. GNU Project       Last change: 1988 December 13                 3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. GREP(1)                  USER COMMANDS                    GREP(1)
  203.  
  204.  
  205.  
  206. AUTHORS
  207.      Mike Haertel wrote the deterministic  regexp  code  and  the
  208.      bulk of the program.
  209.  
  210.      James A. Woods is  responsible  for  the  hybridized  search
  211.      strategy  of using Boyer-Moore-Gosper fixed-string search as
  212.      a filter before calling the general regexp matcher.
  213.  
  214.      Arthur David Olson contributed code that finds fixed strings
  215.      for  the  aforementioned  BMG  search  for  a large class of
  216.      regexps.
  217.  
  218.      Richard Stallman wrote the backtracking regexp matcher  that
  219.      is  used  for  \_d_i_g_i_t  backreferences,  as  well  as the GNU
  220.      getopt.  The backtracking matcher was originally written for
  221.      GNU Emacs.
  222.  
  223.      D. A. Gwyn wrote the C alloca emulation that is provided  so
  224.      System  V  machines  can  run this program.  (Alloca is used
  225.      only by RMS' backtracking matcher, and then only rarely,  so
  226.      there  is  no  loss  if  your  machine doesn't have a "real"
  227.      alloca.)
  228.  
  229.      Scott Anderson and Henry  Spencer  designed  the  regression
  230.      tests used in the "regress" script.
  231.  
  232.      Paul Placeway wrote the  original  version  of  this  manual
  233.      page.
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261. GNU Project       Last change: 1988 December 13                 4
  262.  
  263.  
  264.  
  265.